<template>
    <div class="cont_conter">
        <!--logo-->
        <div class="login_box">
            <div class="logo_name">
                <img src="../assets/logo.jpg"/>
            </div>
          <!--logo-->  

        <el-form :model="form"  :rules="rules" ref="numberValidateForm"  label-width="80px" class="login_f">
        <el-form-item label="个人帐号" prop="username">
            <el-input placeholder="请输入帐号"
    prefix-icon="el-icon-user" style="width: 300px;" v-model="form.username"></el-input>
        </el-form-item>
         <el-form-item label="登录密码" prop="password">
            <el-input  placeholder="请输入密码"
        prefix-icon="el-icon-setting" style="width: 300px;" v-model="form.password" type='password'></el-input>
        </el-form-item>

        <el-form-item class="login_btn">
        <el-button type="warning" @click="resetForm('numberValidateForm')"> 帐号重置</el-button>
         <el-button type="primary" @click="submitForm('numberValidateForm')">确定登录</el-button>
        </el-form-item>
        </el-form>

        </div>
    </div>
</template>

<script>
    export default {
        data () {
            return {
                form: {
                username: 'admin',
                password: '123456',
                },
          rules: {
          username: [
            { required: true, message: '请输入帐号', trigger: 'blur' },
        //    { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          password: [
            { required: true, message: '密码不能为空', trigger: 'blur' }
          ]
            }
        }
      },
      methods: {
        submitForm(formName) {
            this.$refs[formName].validate(async valid => {
            if (valid) {  //预处验证
           const {data:res}=await this.$http.post('login',this.form);
            if(res.meta.status==200){
              this.$message.success('登录成功');
              window.sessionStorage.setItem('token',res.data.token);

              this.$router.push('/home');
            }else{
                return   this.$message.error('登录失败')
            }
            } else {
                return false;
            }
            });
        },
        resetForm(formName) {
         //   console.log(this);
         this.$refs[formName].resetFields();
        }
      }  
    }
</script>

<style scoped>
.cont_conter{
    background-color: blue;
    height: 100%;
}
.login_box {
    width: 600px;
    height: 300px;
    background-color: #fff;
    border-radius: 3px;
    position: absolute;
    left: 50%;
    top:50%;
    transform: translate(-50%,-50%);
}
.logo_name {
    width: 150px;
    height: 150px;
    border: 1px solid #eee;
    padding: 5px;
    box-shadow: 0 0 .3;
    position: absolute;
    left :50%;
    transform: translate(-50%,-130px);
    background-color: #fff;
    border-radius: 50%;

}
.logo_name  img{
    width: 100%;
    height: 100%;
    border-radius: 50%;
    
}
.login_btn {
    margin: 0 auto;
}
.login_f {
    position: absolute;
    top: 60px;
    left: 120px;
}
</style>